%global _empty_manifest_terminate_build 0
Name:           {{ spec_name }}
Version:        {{ version }}
Release:        1
Summary:        {{ pkg_summary }}
License:        {{ pkg_license }}
URL:            {{ pkg_home }}
Source0:        {{ source_url }}
{% if not build_arch %}
BuildArch:      noarch
{% endif %}
%description
{{ description }}

%package -n {{ pkg_name }}
Summary:        {{ pkg_summary }}
Provides:       {{ provides }}
{% if base_build_requires %}
# Base build requires
{% for br in base_build_requires %}
BuildRequires:  {{ br }}
{% endfor %}
{% endif %}
{% if dev_requires %}
# General requires
{% for dr in dev_requires %}
{% if dr not in base_build_requires %}
BuildRequires:  {{ dr }}
{% endif %}
{% endfor %}
{% endif %}
{% if test_requires %}
# Tests running requires
{% for tr in test_requires %}
{% if tr not in base_build_requires %}
BuildRequires:  {{ tr }}
{% endif %}
{% endfor %}
{% endif %}
{% if dev_requires %}
# General requires
{% for dr in dev_requires %}
Requires:       {{ dr }}
{% endfor %}
{% endif %}
{% if test_requires %}
# Tests running requires
{% for tr in test_requires %}
Requires:       {{ tr }}
{% endfor %}
{% endif %}
%description -n {{ pkg_name }}
{{ description }}

%package help
Summary:        {{ pkg_summary }}
Provides:       {{ pkg_name }}-doc
%description help
{{ description }}

%prep
%autosetup -n {{ source_file_dir }}

%build
{% if python2 %}
%py2_build
{% else %}
%py3_build
{% endif %}

%install
{% if python2 %}
%py2_install
{% else %}
%py3_install
{% endif %}

install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
    find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
    find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
    find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
    find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
    find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

{% if add_check %}
%check
{% if python2 %}
%{__python2} setup.py test
{% else %}
%{__python3} setup.py test
{% endif %}
{% endif %}

%files -n {{ pkg_name }} -f filelist.lst
{% if not build_arch %}
{% if python2 %}
%dir %{python2_sitelib}/*
{% else %}
%dir %{python3_sitelib}/*
{% endif %}
{% else %}
{% if python2 %}
%dir %{python2_sitearch}/*
{% else %}
%dir %{python3_sitearch}/*
{% endif %}
{% endif %}

%files help -f doclist.lst
%{_docdir}/*

%changelog
* {{ today }} OpenStack_SIG <openstack@openeuler.org> - {{ version }}-1
{% if change_log %}
- {{ change_log }}
{% else %}
{% if old_changelog %}
- {{ up_down_grade }} package {{ pkg_name }} to version {{ version }}
{% else %}
- Init package {{ pkg_name }} of version {{ version }}
{% endif %}
{% endif %}

{% if old_changelog %}
{% for cl in old_changelog %}
{{ cl }}
{% endfor %}
{% endif %}
